<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">
<script>
    (function () {
        if ('') {
            if (prompt('请输入文章密码') !== '') {
                alert('密码错误！');
                if (history.length === 1) {
                    location.replace("https://google.com"); // 这里替换成你的首页
                } else {
                    history.back();
                }
            }
        }
    })();
</script>








<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="linux,">










<meta name="description" content="sed123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475删除某行对98k.txt的行进行操作，将操作结果输出到终端（只是做模拟操作，不改动源文件）sed &quot;1d&quot; 98">
<meta name="keywords" content="linux">
<meta property="og:type" content="article">
<meta property="og:title" content="linux常用命令收集">
<meta property="og:url" content="http://yoursite.com/2018/12/27/linux-常用命令/index.html">
<meta property="og:site_name" content="苏生不惑的博客">
<meta property="og:description" content="sed123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475删除某行对98k.txt的行进行操作，将操作结果输出到终端（只是做模拟操作，不改动源文件）sed &quot;1d&quot; 98">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-10-16T12:05:50.546Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="linux常用命令收集">
<meta name="twitter:description" content="sed123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475删除某行对98k.txt的行进行操作，将操作结果输出到终端（只是做模拟操作，不改动源文件）sed &quot;1d&quot; 98">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/12/27/linux-常用命令/">



<meta name="referrer" content="never"> ​​​​


  <title>linux常用命令收集 | 苏生不惑的博客</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">苏生不惑的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/12/27/linux-常用命令/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">linux常用命令收集</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-12-27T10:14:14+08:00">
                2018-12-27
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  5.9k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  27 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="sed"><a href="#sed" class="headerlink" title="sed"></a>sed</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br></pre></td><td class="code"><pre><span class="line">删除某行</span><br><span class="line"></span><br><span class="line">对<span class="number">98</span>k.txt的行进行操作，将操作结果输出到终端（只是做模拟操作，不改动源文件）</span><br><span class="line"></span><br><span class="line">sed "1d" 98k.txt         # 输出删除第一行后的文件内容</span><br><span class="line">sed "$d" 98k.txt         # 输出删除最后一行后的文件内容</span><br><span class="line">sed "1,2d" 98k.txt       # 输出删除第一行到第二行后的文件内容</span><br><span class="line">sed "2,$d" 98k.txt       # 输出删除第2行到最后1行后的文件内容</span><br><span class="line"></span><br><span class="line">显示某行</span><br><span class="line"></span><br><span class="line">sed -n "1p" 98k.txt           # 只显示文件的第一行 </span><br><span class="line">sed -n "$p" 98k.txt           # 只显示文件的最后一行</span><br><span class="line">sed -n "1,2p" 98k.txt         # 只显示文件的第一行到第二行</span><br><span class="line">sed -n "2,$p" 98k.txt         # 显示文件的第二行到最后一行</span><br><span class="line"></span><br><span class="line">使用安静模式进行查询</span><br><span class="line"></span><br><span class="line">sed -n <span class="string">"/ruby/p"</span> <span class="number">98</span>k.txt</span><br><span class="line">输出关键字ruby所在行的内容；其中<span class="string">"/str/p"</span>，str为搜索的文本内容</span><br><span class="line">sed -n <span class="string">"/\$/p"</span> <span class="number">98</span>k.txt</span><br><span class="line">输出关键字$所在行的内容，使用反斜线\屏蔽特殊含义</span><br><span class="line"></span><br><span class="line">增加一行或多行字符串</span><br><span class="line"></span><br><span class="line">sed "1a drink tea" 98k.txt            # 在第一行后增加字符串"drink tea"</span><br><span class="line">sed "1,3a drink tea" 98k.txt          # 在第一行到第三行后增加字符串"drink tea"</span><br><span class="line">sed "1a drink tea\nor coffee" 98k.txt # 在第一行后增加两行，换行使用\n，可多次使用\n添加多行</span><br><span class="line"></span><br><span class="line">增加另外一个文件的内容</span><br><span class="line"></span><br><span class="line">sed "1r 1.txt" 98k.txt     # 把1.txt的内容增加到98k.txt的第一行后</span><br><span class="line"></span><br><span class="line">替代一行或多行</span><br><span class="line"></span><br><span class="line">sed "1c Hi" 98k.txt    # 把98k.txt的第一行替换为Hi</span><br><span class="line">sed "1,2c Hi" 98k.txt  # 把98k.txt的第一行到第二行替换为Hi</span><br><span class="line"></span><br><span class="line">替换一行中的某部分字符串</span><br><span class="line"></span><br><span class="line">格式：sed <span class="string">"s/要替换的字符串/新的字符串/g"</span> <span class="number">98</span>k.txt （要替换的字符串可以用正则表达式）</span><br><span class="line"></span><br><span class="line">sed "s/ruby/bird/g" 98k.txt   # 把全部的ruby替换为bird</span><br><span class="line">sed "s/ruby//g" 98k.txt       # 把全部的ruby替换为空，即删除ruby字符串</span><br><span class="line"></span><br><span class="line"># 对每行匹配到的第一个字符串进行替换</span><br><span class="line">sed -i <span class="string">"s/原字符串/新字符串/"</span> <span class="number">98</span>k.txt</span><br><span class="line"></span><br><span class="line"># 对全局匹配上的所有字符串进行替换</span><br><span class="line">sed -i <span class="string">"s/原字符串/新字符串/g"</span> <span class="number">98</span>k.txt</span><br><span class="line"></span><br><span class="line"># 删除所有匹配到字符串的行</span><br><span class="line">sed -i <span class="string">"/匹配字符串/d"</span>  <span class="number">98</span>k.txt</span><br><span class="line"></span><br><span class="line"># 特定字符串的行后插入新行</span><br><span class="line">sed -i <span class="string">"/特定字符串/a 新行字符串"</span> <span class="number">98</span>k.txt</span><br><span class="line"></span><br><span class="line"># 特定字符串的行前插入新行</span><br><span class="line">sed -i <span class="string">"/特定字符串/i 新行字符串"</span> <span class="number">98</span>k.txt</span><br><span class="line"></span><br><span class="line"># 把匹配行中的某个字符串替换为目标字符串</span><br><span class="line">sed -i <span class="string">"/匹配字符串/s/源字符串/目标字符串/g"</span> <span class="number">98</span>k.txt</span><br><span class="line"></span><br><span class="line"># 在文件98k.txt中的末行之后，添加bye</span><br><span class="line">sed -i <span class="string">"$a bye"</span> <span class="number">98</span>k.txt</span><br><span class="line"></span><br><span class="line"># 对于文件第3行，把匹配上的所有字符串进行替换</span><br><span class="line">sed -i <span class="string">"3s/原字符串/新字符串/g"</span> <span class="number">98</span>k.txt</span><br><span class="line"></span><br><span class="line">echo hello|sed 's/hello/(&amp;)/' #将hello放在扩号中</span><br><span class="line">sed -i <span class="string">'/DEVICE/c\Ethernet'</span> test </span><br><span class="line">nl /etc/passwd | sed <span class="string">'2i drink tea'</span> </span><br><span class="line">sed -i '/connect/s#YES#NO#' test    #匹配connect的行，把YES替换成NO </span><br><span class="line"> 将文件的分隔符从逗号更改为管道</span><br><span class="line">head mydata.csv | sed <span class="string">'s/,/|/g'</span></span><br></pre></td></tr></table></figure>
<h3 id="sort"><a href="#sort" class="headerlink" title="sort"></a>sort</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line">sort [-fbMnrtuk] [file or stdin]</span><br><span class="line">选项与参数：</span><br><span class="line">-f  ：忽略大小写的差异，例如 A 与 a 视为编码相同；</span><br><span class="line">-b  ：忽略最前面的空格符部分；</span><br><span class="line">-M  ：以月份的名字来排序，例如 JAN, DEC 等等的排序方法；</span><br><span class="line">-n  ：使用『纯数字』进行排序(默认是以文字型态来排序的)；</span><br><span class="line">-r  ：反向排序；</span><br><span class="line">-u  ：就是 uniq ，相同的数据中，仅出现一行代表；</span><br><span class="line">-t  ：分隔符，默认是用 [tab] 键来分隔；</span><br><span class="line">-k  ：以那个区间 (field) 来进行排序的意思</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line">sort -m file1 file2 合并两个文件</span><br><span class="line">sort file1&gt;file1；cat file1，你会得到一个空文件。这时候要使用-o参数来实现这个功能。</span><br><span class="line">-n是按照数字大小排序，-r是以相反顺序，-k是指定需要爱排序的栏位，-t指定栏位分隔符为冒号</span><br><span class="line">sort file1 -o file1</span><br><span class="line">sort -u是全文本去重，而uniq是比较相邻行，将第二个及以后更多重复行删去。</span><br><span class="line">sort file2 |uniq -c file</span><br><span class="line">删除重复行：</span><br><span class="line"></span><br><span class="line">　　uniq file.txt 　　</span><br><span class="line"></span><br><span class="line">　　sort file.txt | uniq 　　</span><br><span class="line"></span><br><span class="line">　　sort -u file.txt</span><br><span class="line"></span><br><span class="line">　　只显示单一行：</span><br><span class="line"></span><br><span class="line">　　uniq -u file.txt 　　</span><br><span class="line"></span><br><span class="line">　　sort file.txt | uniq -u</span><br><span class="line"></span><br><span class="line">　　统计各行在文件中出现的次数：</span><br><span class="line"></span><br><span class="line">　　sort file.txt | uniq -c</span><br><span class="line"></span><br><span class="line">　　在文件中找出重复的行：</span><br><span class="line"></span><br><span class="line">　　sort file.txt | uniq -d</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line">　　利用sort和uniq求两个文件的并集，交集和差集</span><br><span class="line"></span><br><span class="line">　　并集：cat file1.txt file2.txt | sort | uniq &gt; file.txt</span><br><span class="line"></span><br><span class="line">　　交集：cat file1.txt file2.txt | sort | uniq -d &gt;file.txt</span><br><span class="line"></span><br><span class="line">　　差集：求file1.txt相对于file2.txt的差集，可先求出两者的交集temp.txt，然后在file1.txt中除去temp.txt即可。</span><br><span class="line"></span><br><span class="line">　　　　　cat file1.txt file2.txt | sort | uniq -d &gt;temp.txt</span><br><span class="line"></span><br><span class="line">　　　　　cat file1.txt temp.txt | sort | uniq -u &gt;file.txt</span><br><span class="line">sort -u 会达到和典型的 sort file.txt | uniq 模式一样的结果</span><br><span class="line">sort -t<span class="string">","</span> -k2,<span class="number">2</span> filename.csv</span><br><span class="line">egrep <span class="string">"php.*artisan"</span> 匹配php artisan</span><br><span class="line">grep <span class="string">"first_value\|second_value"</span> filename.csv</span><br></pre></td></tr></table></figure>
<h3 id="cut"><a href="#cut" class="headerlink" title="cut"></a>cut</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">删除第一和第三列cut -d, -f <span class="number">1</span>,<span class="number">3</span> filename.csv</span><br></pre></td></tr></table></figure>
<h3 id="合并文件"><a href="#合并文件" class="headerlink" title="合并文件"></a>合并文件</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"># names.txt</span><br><span class="line">adam</span><br><span class="line">john</span><br><span class="line">zach</span><br><span class="line"># jobs.txt</span><br><span class="line">lawyer</span><br><span class="line">youtuber</span><br><span class="line">developer</span><br><span class="line"># Join the two into a CSV</span><br><span class="line">paste -d <span class="string">','</span> names.txt jobs.txt &gt; person_data.txt</span><br><span class="line"># Output</span><br><span class="line">adam,lawyer</span><br><span class="line">john,youtuber</span><br><span class="line">zach,developer</span><br></pre></td></tr></table></figure>
<h3 id="awk"><a href="#awk" class="headerlink" title="awk"></a>awk</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br></pre></td><td class="code"><pre><span class="line">awk -F<span class="string">":"</span> <span class="string">'&#123;print $1&#125;'</span>  /etc/passwd</span><br><span class="line"> awk -F":" '&#123;print $1,$3&#125;'  /etc/passwd                          #多了一个逗号，$1与$3使用空格分隔</span><br><span class="line"> awk -F":" '&#123;print "Username:" $1 "\t\t Uid:" $3 &#125;' /etc/passwd  #自定义输出  </span><br><span class="line"> awk -F: '&#123;print NF&#125;' /etc/passwd                                #显示每行有多少字段</span><br><span class="line"> awk -F: '&#123;print $NF&#125;' /etc/passwd                               #将每行第NF个字段的值打印出来</span><br><span class="line"> awk -F: 'NF==4 &#123;print&#125;' /etc/passwd                             #显示只有4个字段的行</span><br><span class="line"> awk -F: 'NF&gt;2&#123;print $0&#125;' /etc/passwd                            #显示每行字段数量大于2的行</span><br><span class="line"> awk -F: '&#123;print NR,NF,$NF,"\t",$0&#125;' /etc/passwd                 #依次打印行号，字段数，最后字段值，制表符，每行内容</span><br><span class="line"> awk -F: 'NR==5 || NR==6&#123;print&#125;'  /etc/passwd                    #显示第5行和第6行</span><br><span class="line"> <span class="comment">//匹配代码块</span></span><br><span class="line"> <span class="comment">//纯字符匹配   !//纯字符不匹配   ~//字段值匹配    !~//字段值不匹配   ~/a1|a2/字段值匹配a1或a2   </span></span><br><span class="line"> awk '/mysql/&#123;print $0&#125;' /etc/passwd              #三条指令结果一样</span><br><span class="line"> awk '!/mysql/&#123;print $0&#125;' /etc/passwd             #输出不匹配mysql的行</span><br><span class="line"> awk '!/mysql|mail/&#123;print&#125;' /etc/passwd           #输出不匹配mysql或mail的行</span><br><span class="line"> awk '/[2][7][7]*/&#123;print $0&#125;' /etc/passwd         #匹配包含27为数字开头的行，如27，277，2777...</span><br><span class="line"> awk -F: '$1~/mail/&#123;print $1&#125;' /etc/passwd        #$1匹配指定内容才显示</span><br><span class="line"> awk -F: <span class="string">'$1!~/mail|mysql/&#123;print $1&#125;'</span> /etc/passwd        </span><br><span class="line"></span><br><span class="line"> IF语句 必须用在&#123;&#125;中，且比较内容用()扩起来</span><br><span class="line"> awk -F: <span class="string">'&#123;if($1~/mail/) print $1&#125;'</span> /etc/passwd                                     </span><br><span class="line"> awk -F: <span class="string">'&#123;if($1~/mail/) &#123;print $1&#125;&#125;'</span>  /etc/passwd                              </span><br><span class="line"> awk -F: '&#123;if($1~/mail/) &#123;print $1&#125; else &#123;print $2&#125;&#125;' /etc/passwd  #if...else...</span><br><span class="line"></span><br><span class="line"> 条件表达式 ==   !=   &gt;   &gt;=  </span><br><span class="line"> awk -F<span class="string">":"</span> <span class="string">'&#123;if($1=="mysql") print $3&#125;'</span> /etc/passwd          <span class="comment">//与上面相同 </span></span><br><span class="line"> awk -F<span class="string">":"</span> <span class="string">'$1!="mysql"&#123;print $3&#125;'</span> /etc/passwd               <span class="comment">//不等于</span></span><br><span class="line"> awk -F<span class="string">":"</span> <span class="string">'$3&gt;1000&#123;print $3&#125;'</span> /etc/passwd                   <span class="comment">//大于</span></span><br><span class="line"></span><br><span class="line"> 逻辑运算符 &amp;&amp;　|| </span><br><span class="line"> awk -F: <span class="string">'&#123;if($1~/mail/ &amp;&amp; $3&gt;8) print &#125;'</span> /etc/passwd</span><br><span class="line"> awk -F: <span class="string">'&#123;if($1~/mail/ || $3&gt;1000) print &#125;'</span> /etc/passwd </span><br><span class="line"> 删除重复行</span><br><span class="line"> </span><br><span class="line"> $ awk <span class="string">'!($0 in array) &#123; array[$0]; print&#125;'</span> temp</span><br><span class="line"> 打印/etc/passwd中所有包含同样的uid和gid的行</span><br><span class="line"> </span><br><span class="line"> $ awk -F <span class="string">':'</span> <span class="string">'$3=$4'</span> /etc/passwd</span><br><span class="line"> 打印文件中的指定部分的字段</span><br><span class="line"> </span><br><span class="line"> $ awk <span class="string">'&#123;print $2,$5;&#125;'</span> employee.txt</span><br><span class="line"> 比较的时候忽略空白符</span><br><span class="line"> </span><br><span class="line"> $ diff -w name_list.txt name_list_new.txt</span><br><span class="line"> 下载文件中列出的所有url对应的页面</span><br><span class="line"> </span><br><span class="line"> $ cat url-list.txt | xargs wget –c</span><br><span class="line"> #替代grep</span><br><span class="line"> awk <span class="string">'/word/'</span> filename.csv</span><br><span class="line"> 对于所有带我们指定单词 word 的行，awk 打印第三和第四列，用 tab 分隔。-F, 用于指定切分时的列分隔符为逗号。</span><br><span class="line"> awk -F, <span class="string">'/word/ &#123; print $3 "\t" $4 &#125;'</span> filename.csv</span><br><span class="line"> 要获取文件中的第 <span class="number">53</span> 条记录</span><br><span class="line"> awk -F, <span class="string">'NR == 53'</span> filename.csv</span><br><span class="line"> 打印第一列等于给定字符串的行的行号和列</span><br><span class="line"> awk -F, <span class="string">' $1 == "string" &#123; print NR, $0 &#125; '</span> filename.csv</span><br><span class="line"> awk -F, <span class="string">' $3 &gt;= 2005 &amp;&amp; $5 &lt;= 1000 &#123; print NR, $0 &#125; '</span> filename.csv</span><br><span class="line"> 求出第三列的总和</span><br><span class="line"> awk -F, <span class="string">'&#123; x+=$3 &#125; END &#123; print x &#125;'</span> filename.csv</span><br><span class="line"> 组合多个 CSV 文件，忽略标题，然后在最后附加它</span><br><span class="line"> awk <span class="string">'FNR==1 &amp;&amp; NR!=1&#123;next;&#125;&#123;print&#125;'</span> *.csv &gt; final_file.csv</span><br><span class="line"> 内置函数 gsub() 替换多个值</span><br><span class="line"> awk <span class="string">'&#123;gsub(/scarlet|ruby|puce/, "red"); print&#125;'</span></span><br><span class="line"> 打印出现了两次的行</span><br><span class="line"> awk -F, <span class="string">'++seen[$0] == 2'</span> filename.csv</span><br><span class="line"> 获取文件的行列数：</span><br><span class="line"> awk -F, <span class="string">'END &#123; print NF, NR &#125;'</span> filename.csv</span><br><span class="line"> # Prettier version</span><br><span class="line"> awk -F, <span class="string">'BEGIN &#123; print "COLUMNS", "ROWS" &#125;; END &#123; print NF, NR &#125;'</span> filename.csv</span><br><span class="line">根据第一列去重，相同的保留第二列值最大的那个https:<span class="comment">//segmentfault.com/q/1010000000665713</span></span><br><span class="line">fdf     <span class="number">284</span> </span><br><span class="line">asd     <span class="number">112</span></span><br><span class="line">adf     <span class="number">146</span></span><br><span class="line">csb     <span class="number">513</span></span><br><span class="line">dfg     <span class="number">576</span></span><br><span class="line">asd     <span class="number">346</span></span><br><span class="line">adf     <span class="number">263</span></span><br><span class="line">csb     <span class="number">092</span></span><br><span class="line">dfg     <span class="number">547</span></span><br><span class="line">[root@VM_0_14_centos ~]# cat awk.txt | sort -rnk2 | awk '&#123;if (!keys[$1]) print $0; keys[$1] = 1;&#125;'</span><br><span class="line">dfg     <span class="number">576</span></span><br><span class="line">csb     <span class="number">513</span></span><br><span class="line">asd     <span class="number">346</span></span><br><span class="line">fdf     <span class="number">284</span></span><br><span class="line">adf     <span class="number">263</span></span><br><span class="line">先按第二列数字大小逆序，然后再按第一列去重，这样就能得到第二列最大的非重复行数据。</span><br><span class="line">[root@VM_0_14_centos ~]# sort -rnk2,2 awk.txt |sort -uk1,1</span><br><span class="line"></span><br><span class="line">adf     <span class="number">263</span></span><br><span class="line">asd     <span class="number">346</span></span><br><span class="line">csb     <span class="number">513</span></span><br><span class="line">dfg     <span class="number">576</span></span><br><span class="line">fdf     <span class="number">284</span></span><br><span class="line">第一列等于 something 的那些行，求出第三列值的总和</span><br><span class="line">awk -F, <span class="string">'$1 == "something" &#123; x+=$3 &#125; END &#123; print x &#125;'</span> filename.csv</span><br></pre></td></tr></table></figure>
<h3 id="快捷键"><a href="#快捷键" class="headerlink" title="快捷键"></a>快捷键</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ bind -p</span><br><span class="line"><span class="string">"\C-g"</span>: abort</span><br><span class="line"><span class="string">"\C-x\C-g"</span>: abort</span><br><span class="line"><span class="string">"\e\C-g"</span>: abort</span><br><span class="line"><span class="string">"\C-j"</span>: accept-line</span><br><span class="line">查找所有使用了Control键的绑定https:<span class="comment">//gywbd.github.io/posts/2014/11/linux-keybindings.html</span></span><br><span class="line">$ bind -p | grep <span class="string">'\\c'</span></span><br></pre></td></tr></table></figure>
<h3 id="解压"><a href="#解压" class="headerlink" title="解压"></a>解压</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">创建一个新的tar文件</span><br><span class="line"></span><br><span class="line">$ tar cvf archive_name.tar dirname/</span><br><span class="line">解压tar文件</span><br><span class="line"></span><br><span class="line">$ tar xvf archive_name.tar</span><br><span class="line">查看tar文件</span><br><span class="line"></span><br><span class="line">$ tar tvf archive_name.tar</span><br></pre></td></tr></table></figure>
<h3 id="测试并发"><a href="#测试并发" class="headerlink" title="测试并发"></a>测试并发</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">ab -n <span class="number">100</span> -c <span class="number">10</span> -l http:<span class="comment">//www.your_site.com</span></span><br><span class="line">-n number 总的请求数</span><br><span class="line">-c concurrency 并发数 </span><br><span class="line">-l 表示当某个请求的回复长度不与第一个请求的回复长度一致时，不把它作为失败的请求</span><br><span class="line">POST方法：https:<span class="comment">//shuwoom.com/?p=1542</span></span><br><span class="line"></span><br><span class="line">ab -n <span class="number">100</span> -c <span class="number">10</span> -p post.txt http:<span class="comment">//xxx/test.php</span></span><br><span class="line">post.txt里面是参数，如data=&#123;<span class="string">"name"</span>:<span class="string">"wgc"</span>&#125;，但是要url编码以后的参数</span><br></pre></td></tr></table></figure>
<h3 id="查看当前目录下各个文件或文件夹的大小"><a href="#查看当前目录下各个文件或文件夹的大小" class="headerlink" title="查看当前目录下各个文件或文件夹的大小"></a>查看当前目录下各个文件或文件夹的大小</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_14_centos ~]# du -h --max-depth=1 .</span><br><span class="line"><span class="number">7.5</span>M    ./.config</span><br><span class="line"><span class="number">5.8</span>M    ./imgbed-project</span><br><span class="line"><span class="number">1.7</span>M    ./Chatroom</span><br><span class="line"><span class="number">8.0</span>K    ./.httpie</span><br><span class="line"><span class="number">20</span>K     ./.ssh</span><br><span class="line"><span class="number">2.7</span>M    ./lnmp-docker</span><br><span class="line"><span class="number">101</span>M    ./daily-signer</span><br><span class="line"><span class="number">708</span>K    ./pick<span class="number">-1.9</span><span class="number">.0</span></span><br><span class="line"><span class="number">32</span>M     ./gaga</span><br><span class="line"><span class="number">688</span>K    ./.acme.sh</span><br><span class="line"><span class="number">1.9</span>M    ./dockser-server</span><br><span class="line"><span class="number">3.4</span>M    ./shadowsocksr</span><br></pre></td></tr></table></figure>
<h3 id="查找字符串"><a href="#查找字符串" class="headerlink" title="查找字符串"></a>查找字符串</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">find .<span class="comment">/*|xargs grep debug</span></span><br><span class="line"><span class="comment">#https://github.com/BurntSushi/ripgrep/</span></span><br><span class="line"><span class="comment">[root@VM_0_14_centos ~]# rg 'redis'</span></span><br><span class="line"><span class="comment">imgbed-project/LICENSE</span></span><br><span class="line"><span class="comment">627:free software which everyone can redistribute and change under these terms.</span></span><br><span class="line"><span class="comment">637:    This program is free software: you can redistribute it and/or modify</span></span><br><span class="line"><span class="comment">657:    This is free software, and you are welcome to redistribute it</span></span><br></pre></td></tr></table></figure>
<h3 id="Nginx-日志统计-ip-访问数"><a href="#Nginx-日志统计-ip-访问数" class="headerlink" title="Nginx 日志统计 ip 访问数"></a>Nginx 日志统计 ip 访问数</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line">切割日志</span><br><span class="line"></span><br><span class="line">查找<span class="number">7</span>月<span class="number">17</span>日访问log导出到<span class="number">17.</span>log文件中：</span><br><span class="line"></span><br><span class="line">cat gelin_web_access.log | egrep <span class="string">"17/Jul/2017"</span> | sed  -n <span class="string">'/00:00:00/,/23:59:59/p'</span> &gt; <span class="regexp">/tmp/</span><span class="number">17.</span>log</span><br><span class="line">查看访问量前<span class="number">10</span>的IP</span><br><span class="line"></span><br><span class="line">awk <span class="string">'&#123;print $1&#125;'</span> <span class="number">17.</span>log | sort | uniq -c | sort -nr | head -n <span class="number">10</span> </span><br><span class="line">查看访问前<span class="number">10</span>的URL</span><br><span class="line"></span><br><span class="line">awk <span class="string">'&#123;print $11&#125;'</span> gelin_web_access.log | sort | uniq -c | sort -nr | head -n <span class="number">10</span></span><br><span class="line">查询访问最频繁的URL</span><br><span class="line"></span><br><span class="line">awk <span class="string">'&#123;print $7&#125;'</span> gelin_web_access.log | sort | uniq -c | sort -n -k <span class="number">1</span> -r | more</span><br><span class="line">查询访问最频繁的IP</span><br><span class="line"></span><br><span class="line">awk <span class="string">'&#123;print $1&#125;'</span> gelin_web_access.log | sort | uniq -c | sort -n -k <span class="number">1</span> -r | more</span><br><span class="line">根据访问IP统计UV</span><br><span class="line"></span><br><span class="line">awk <span class="string">'&#123;print $1&#125;'</span> gelin_web_access.log | sort | uniq -c | wc -l</span><br><span class="line">统计访问URL统计PV</span><br><span class="line"></span><br><span class="line">awk <span class="string">'&#123;print $7&#125;'</span> gelin_web_access.log | wc -l</span><br><span class="line">根据时间段统计查看日志</span><br><span class="line"></span><br><span class="line">cat gelin_web_access.log | sed -n <span class="string">'/17\/Jul\/2017:12/,/17\/Jul\/2017:13/p'</span> | more</span><br><span class="line">[root@VM_0_14_centos ~]# cat /var/log/nginx/access.log|more</span><br><span class="line"><span class="number">120.132</span><span class="number">.3</span><span class="number">.65</span> - - [<span class="number">21</span>/Dec/<span class="number">2018</span>:<span class="number">06</span>:<span class="number">28</span>:<span class="number">57</span> +<span class="number">0800</span>] <span class="string">"GET http://www.qq.com/404/search_children.js HTTP/1.1"</span> <span class="number">404</span> <span class="number">3650</span> <span class="string">"-"</span> <span class="string">"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36"</span> <span class="string">"-"</span></span><br><span class="line"><span class="number">120.132</span><span class="number">.3</span><span class="number">.65</span> - - [<span class="number">21</span>/Dec/<span class="number">2018</span>:<span class="number">06</span>:<span class="number">28</span>:<span class="number">57</span> +<span class="number">0800</span>] <span class="string">"\x04\x01\x00PpTi4\x00"</span> <span class="number">400</span> <span class="number">173</span> <span class="string">"-"</span> <span class="string">"-"</span> <span class="string">"-"</span></span><br><span class="line"><span class="number">120.132</span><span class="number">.3</span><span class="number">.65</span> - - [<span class="number">21</span>/Dec/<span class="number">2018</span>:<span class="number">06</span>:<span class="number">28</span>:<span class="number">57</span> +<span class="number">0800</span>] <span class="string">"\x05\x01\x00"</span> <span class="number">400</span> <span class="number">173</span> <span class="string">"-"</span> <span class="string">"-"</span> <span class="string">"-"</span></span><br><span class="line"><span class="number">58.150</span><span class="number">.60</span><span class="number">.162</span> - manager [<span class="number">21</span>/Dec/<span class="number">2018</span>:<span class="number">08</span>:<span class="number">08</span>:<span class="number">21</span> +<span class="number">0800</span>] <span class="string">"POST /WEB_VMS/LEVEL15/ HTTP/1.1"</span> <span class="number">404</span> <span class="number">3650</span> <span class="string">"-"</span> <span class="string">"-"</span> <span class="string">"-"</span></span><br><span class="line"><span class="number">95.213</span><span class="number">.177</span><span class="number">.123</span> - - [<span class="number">21</span>/Dec/<span class="number">2018</span>:<span class="number">08</span>:<span class="number">36</span>:<span class="number">15</span> +<span class="number">0800</span>] <span class="string">"CONNECT check.proxyradar.com:80 HTTP/1.1"</span> <span class="number">400</span> <span class="number">173</span> <span class="string">"-"</span> <span class="string">"-"</span> <span class="string">"-"</span></span><br><span class="line"><span class="number">60.191</span><span class="number">.52</span><span class="number">.254</span> - - [<span class="number">21</span>/Dec/<span class="number">2018</span>:<span class="number">09</span>:<span class="number">35</span>:<span class="number">18</span> +<span class="number">0800</span>] <span class="string">"HEAD http://112.124.42.80:63435/ HTTP/1.1"</span> <span class="number">200</span> <span class="number">0</span> <span class="string">"-"</span> <span class="string">"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"</span> <span class="string">"-"</span></span><br><span class="line"><span class="number">80.82</span><span class="number">.70</span><span class="number">.187</span> - - [<span class="number">21</span>/Dec/<span class="number">2018</span>:<span class="number">09</span>:<span class="number">47</span>:<span class="number">37</span> +<span class="number">0800</span>] <span class="string">"GET http://www.baidu.com/cache/global/img/gs.gif HTTP/1.1"</span> <span class="number">404</span> <span class="number">3650</span> <span class="string">"-"</span> <span class="string">"Mozilla"</span> <span class="string">"-"</span></span><br><span class="line"><span class="number">139.162</span><span class="number">.81</span><span class="number">.62</span> - - [<span class="number">21</span>/Dec/<span class="number">2018</span>:<span class="number">10</span>:<span class="number">33</span>:<span class="number">03</span> +<span class="number">0800</span>] <span class="string">"GET http://clientapi.ipip.net/echo.php?info=1234567890 HTTP/1.1"</span> <span class="number">404</span> <span class="number">3650</span> <span class="string">"-"</span> <span class="string">"Go-http-client/1.1"</span> <span class="string">"-"</span></span><br><span class="line">[root@VM_0_14_centos ~]# cat /var/log/nginx/access.log|awk '&#123;print $1&#125;'|sort|uniq -c|sort -nrk1</span><br><span class="line">      <span class="number">3</span> <span class="number">120.132</span><span class="number">.3</span><span class="number">.65</span></span><br><span class="line">      <span class="number">1</span> <span class="number">95.213</span><span class="number">.177</span><span class="number">.123</span></span><br><span class="line">      <span class="number">1</span> <span class="number">80.82</span><span class="number">.78</span><span class="number">.50</span></span><br><span class="line">      <span class="number">1</span> <span class="number">80.82</span><span class="number">.70</span><span class="number">.187</span></span><br><span class="line">      <span class="number">1</span> <span class="number">60.191</span><span class="number">.52</span><span class="number">.254</span></span><br><span class="line">      <span class="number">1</span> <span class="number">58.150</span><span class="number">.60</span><span class="number">.162</span></span><br><span class="line">      <span class="number">1</span> <span class="number">139.162</span><span class="number">.81</span><span class="number">.62</span></span><br><span class="line">at /<span class="keyword">var</span>/log/nginx/access.log|awk <span class="string">'&#123;ipArr[$1]++&#125; END&#123;for( item in ipArr) print item,ipArr[item]&#125;'</span> | sort -r -k</span><br><span class="line"><span class="number">2</span></span><br><span class="line"><span class="number">1.</span>根据访问IP统计UV</span><br><span class="line">awk <span class="string">'&#123;print $1&#125;'</span> access.log|sort | uniq -c |wc -l</span><br><span class="line"></span><br><span class="line"><span class="number">2.</span>统计访问URL统计PV</span><br><span class="line">awk <span class="string">'&#123;print $7&#125;'</span> access.log|wc -l</span><br><span class="line"></span><br><span class="line"><span class="number">3.</span>查询访问最频繁的URL</span><br><span class="line">awk <span class="string">'&#123;print $7&#125;'</span> access.log|sort | uniq -c |sort -n -k <span class="number">1</span> -r|more</span><br><span class="line"></span><br><span class="line"><span class="number">4.</span>查询访问最频繁的IP</span><br><span class="line">awk <span class="string">'&#123;print $1&#125;'</span> access.log|sort | uniq -c |sort -n -k <span class="number">1</span> -r|more</span><br><span class="line"></span><br><span class="line"><span class="number">5.</span>根据时间段统计查看日志</span><br><span class="line">cat access.log| sed -n <span class="string">'/14\/Mar\/2015:21/,/14\/Mar\/2015:22/p'</span>|more</span><br></pre></td></tr></table></figure>
<h3 id="文件比较（交集、差集）"><a href="#文件比较（交集、差集）" class="headerlink" title="文件比较（交集、差集）"></a>文件比较（交集、差集）</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">交集（打印两个文件相同的行）</span><br><span class="line">[root@VM_0_14_centos ~]# cat aaa.txt</span><br><span class="line">aaa</span><br><span class="line">bbb</span><br><span class="line">ccc</span><br><span class="line">ddd</span><br><span class="line">eee</span><br><span class="line"><span class="number">111</span></span><br><span class="line"><span class="number">222</span></span><br><span class="line">[root@VM_0_14_centos ~]# cat bbb.txt</span><br><span class="line">bbb</span><br><span class="line">ccc</span><br><span class="line">aaa</span><br><span class="line">hhh</span><br><span class="line">ttt</span><br><span class="line">jjj</span><br><span class="line">[root@VM_0_14_centos ~]# comm -12 &lt;(sort aaa.txt) &lt;(sort bbb.txt)</span><br><span class="line">aaa</span><br><span class="line">bbb</span><br><span class="line">ccc</span><br><span class="line">求差（打印两个文件中不相同的行）</span><br><span class="line">[root@VM_0_14_centos ~]# comm -3 &lt;(sort aaa.txt) &lt;(sort bbb.txt)</span><br><span class="line"><span class="number">111</span></span><br><span class="line"><span class="number">222</span></span><br><span class="line">ddd</span><br><span class="line">eee</span><br><span class="line">        hhh</span><br><span class="line">        jjj</span><br><span class="line">        ttt</span><br><span class="line">[root@VM_0_14_centos ~]# comm -3 &lt;(sort aaa.txt) &lt;(sort bbb.txt)|sed 's/^\t//' </span><br><span class="line"><span class="number">111</span>                                                                            </span><br><span class="line"><span class="number">222</span>                                                                            </span><br><span class="line">ddd                                                                            </span><br><span class="line">eee                                                                            </span><br><span class="line">hhh                                                                            </span><br><span class="line">jjj                                                                            </span><br><span class="line">ttt     </span><br><span class="line">aaa.txt的差集</span><br><span class="line">[root@VM_0_14_centos ~]# comm -23 &lt;(sort aaa.txt) &lt;(sort bbb.txt)</span><br><span class="line"><span class="number">111</span></span><br><span class="line"><span class="number">222</span></span><br><span class="line">ddd</span><br><span class="line">eee</span><br><span class="line">bbb.txt的差集</span><br><span class="line">[root@VM_0_14_centos ~]# comm -13 &lt;(sort aaa.txt) &lt;(sort bbb.txt)</span><br><span class="line">hhh</span><br><span class="line">jjj</span><br><span class="line">ttt</span><br></pre></td></tr></table></figure>
<h3 id="转换编码"><a href="#转换编码" class="headerlink" title="转换编码"></a>转换编码</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">iconv -f ISO<span class="number">-8859</span><span class="number">-1</span> -t UTF<span class="number">-8</span> &lt; input.txt &gt; output.txt</span><br></pre></td></tr></table></figure>
<h3 id="执行算术运算"><a href="#执行算术运算" class="headerlink" title="执行算术运算"></a>执行算术运算</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">expr <span class="number">5</span> + <span class="number">2</span></span><br><span class="line">echo $[16 + 4]#https://www.itcodemonkey.com/article/11866.html</span><br></pre></td></tr></table></figure>
<h3 id="send-email"><a href="#send-email" class="headerlink" title="send email"></a>send email</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_14_centos ~]# wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz</span><br><span class="line">-<span class="number">-2018</span><span class="number">-12</span><span class="number">-20</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">34</span>--  http:<span class="comment">//caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz</span></span><br><span class="line">Resolving caspian.dotconf.net (caspian.dotconf.net)... <span class="number">159.89</span><span class="number">.153</span><span class="number">.157</span></span><br><span class="line">Connecting to caspian.dotconf.net (caspian.dotconf.net)|<span class="number">159.89</span><span class="number">.153</span><span class="number">.157</span>|:<span class="number">80.</span>.. connected.</span><br><span class="line">HTTP request sent, awaiting response... <span class="number">200</span> OK</span><br><span class="line">Length: <span class="number">29740</span> (<span class="number">29</span>K) [application/octet-stream]</span><br><span class="line">Saving to: ‘sendEmail-v1<span class="number">.56</span>.tar.gz’</span><br><span class="line"></span><br><span class="line"><span class="number">100</span>%[===============================================================================================&gt;] <span class="number">29</span>,<span class="number">740</span>       <span class="number">159</span>KB/s   <span class="keyword">in</span> <span class="number">0.2</span>s</span><br><span class="line"></span><br><span class="line"><span class="number">2018</span><span class="number">-12</span><span class="number">-20</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">35</span> (<span class="number">159</span> KB/s) - ‘sendEmail-v1<span class="number">.56</span>.tar.gz’ saved [<span class="number">29740</span>/<span class="number">29740</span>]</span><br><span class="line"></span><br><span class="line">[root@VM_0_14_centos ~]# tar -zxvf sendEmail-v1.56.tar.gz</span><br><span class="line">sendEmail-v1<span class="number">.56</span>/</span><br><span class="line">sendEmail-v1<span class="number">.56</span>/CHANGELOG</span><br><span class="line">sendEmail-v1<span class="number">.56</span>/README</span><br><span class="line">sendEmail-v1<span class="number">.56</span>/README-BR.txt</span><br><span class="line">sendEmail-v1<span class="number">.56</span>/TODO</span><br><span class="line">sendEmail-v1<span class="number">.56</span>/sendEmail</span><br><span class="line">sendEmail-v1<span class="number">.56</span>/sendEmail.pl</span><br><span class="line">[root@VM_0_14_centos ~]# cd sendEmail-v1.56/</span><br><span class="line">[root@VM_0_14_centos sendEmail-v1.56]# mv sendEmail /usr/local/bin</span><br><span class="line">#  /usr/local/bin/sendEmail -f ttlsafrom@163.com -t ttlsato@qq.com \</span><br><span class="line">    -s smtp<span class="number">.163</span>.com -u <span class="string">"我是邮件主题"</span> -o message-content-type=html \</span><br><span class="line">    -o message-charset=utf8 -xu ttlsafrom@<span class="number">163.</span>com -xp <span class="number">123456</span> -m <span class="string">"我是邮件内容"</span></span><br><span class="line">    /usr/local/bin/sendEmail 命令主程序</span><br><span class="line">    -f ttlsafrom@<span class="number">163.</span>com  发件人邮箱</span><br><span class="line">    -s smtp<span class="number">.163</span>.com       发件人邮箱的smtp服务器</span><br><span class="line">    -u <span class="string">"我是邮件主题"</span>     邮件的标题</span><br><span class="line">    -o message-content-type=html   邮件内容的格式,html表示它是html格式</span><br><span class="line">    -o message-charset=utf8        邮件内容编码</span><br><span class="line">    -xu ttlsafrom@<span class="number">163.</span>com          发件人邮箱的用户名</span><br><span class="line">    -xp <span class="number">123456</span>               发件人邮箱密码</span><br><span class="line">    -m <span class="string">"我是邮件内容"</span>        邮件的具体内容</span><br></pre></td></tr></table></figure>
<h3 id="wc"><a href="#wc" class="headerlink" title="wc"></a>wc</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>统计当前目录下，py文件数量：</span><br><span class="line"></span><br><span class="line">find . -name <span class="string">"*.py"</span> |wc -l</span><br><span class="line"><span class="number">2.</span>统计当前目录下，所有py文件行数：</span><br><span class="line"></span><br><span class="line">find . -name <span class="string">"*.py"</span> |xargs cat|wc -l</span><br><span class="line"><span class="number">3.</span>统计当前目录下，所有py文件行数，并过滤空行：</span><br><span class="line"></span><br><span class="line">find . -name <span class="string">"*.py"</span> |xargs cat|grep -v ^$|wc -l</span><br></pre></td></tr></table></figure>
<h3 id="kill"><a href="#kill" class="headerlink" title="kill"></a>kill</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">kill ps -ef | grep <span class="string">'ddd'</span></span><br><span class="line"><span class="keyword">for</span> procid <span class="keyword">in</span> $(ps -aux | grep <span class="string">"some search"</span> | awk <span class="string">'&#123;print $2&#125;'</span>); <span class="keyword">do</span> kill <span class="number">-9</span> $procid; done</span><br><span class="line">ps -ef | grep <span class="string">'ddd'</span> | xargs kill</span><br><span class="line"> echo <span class="string">'--help'</span> | xargs cat 等价于 cat --help</span><br><span class="line"> echo <span class="string">'11@22@33'</span> | xargs -d <span class="string">'@'</span> echo<span class="comment">//11 22 33</span></span><br><span class="line"> echo <span class="string">'11@22@33'</span> | xargs -p -d <span class="string">'@'</span> echo<span class="comment">//不会马上执行其后面的命令，而是输出即将要执行的完整的命令 echo 11 22 33</span></span><br><span class="line"> ?...y ==&gt;这里询问是否执行命令 echo <span class="number">11</span> <span class="number">22</span> <span class="number">33</span> 输入y并回车，则显示执行结果，否则不执行</span><br><span class="line"> https:<span class="comment">//laravel-china.org/articles/21339</span></span><br><span class="line"> find . -name <span class="string">"*.txt"</span></span><br><span class="line"> 输出：</span><br><span class="line"> </span><br><span class="line"> ./<span class="number">2.</span>txt</span><br><span class="line"> ./<span class="number">3.</span>txt</span><br><span class="line"> ./<span class="number">1.</span>txt     =&gt; 默认情况下find的输出结果是每条记录后面加上换行，也就是每条记录是一个新行</span><br><span class="line"> </span><br><span class="line"> find . -name <span class="string">"*.txt"</span> -print0</span><br><span class="line"> 输出：</span><br><span class="line"> </span><br><span class="line"> ./<span class="number">2.</span>txt./<span class="number">3.</span>txt./<span class="number">1.</span>txt     =&gt; 加上 -print0 参数表示find输出的每条结果后面加上 <span class="string">'\0'</span> 而不是换行</span><br><span class="line"> </span><br><span class="line"> find . -name <span class="string">"*.txt"</span> -print0 | xargs <span class="number">-0</span> echo</span><br><span class="line"> 输出：</span><br><span class="line"> </span><br><span class="line"> ./<span class="number">2.</span>txt ./<span class="number">3.</span>txt ./<span class="number">1.</span>txt</span><br><span class="line"> </span><br><span class="line"> find . -name <span class="string">"*.txt"</span> -print0 | xargs -d <span class="string">'\0'</span> echo</span><br><span class="line"> 输出：</span><br><span class="line"> ./<span class="number">2.</span>txt ./<span class="number">3.</span>txt ./<span class="number">1.</span>txt</span><br></pre></td></tr></table></figure>
<h3 id="uniq"><a href="#uniq" class="headerlink" title="uniq"></a>uniq</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">#uniq -h</span><br><span class="line">长选项必须使用的参数对于短选项时也是必需使用的。  </span><br><span class="line"> -c, --count              <span class="comment">//在每行前加上表示相应行目出现次数的前缀编号  </span></span><br><span class="line"> -d, --repeated          <span class="comment">//只输出重复的行  </span></span><br><span class="line"> -D, --all-repeated      <span class="comment">//只输出重复的行，不过有几行输出几行  </span></span><br><span class="line"> -f, --skip-fields=N     <span class="comment">//-f 忽略的段数，-f 1 忽略第一段  </span></span><br><span class="line"> -i, --ignore-<span class="keyword">case</span>       <span class="comment">//不区分大小写  </span></span><br><span class="line"> -s, --skip-chars=N      <span class="comment">//根-f有点像，不过-s是忽略，后面多少个字符 -s 5就忽略后面5个字符  </span></span><br><span class="line"> -u, --unique            <span class="comment">//去除重复的后，全部显示出来，根mysql的distinct功能上有点像  </span></span><br><span class="line"> -z, --zero-terminated   end lines <span class="keyword">with</span> <span class="number">0</span> byte, not newline  </span><br><span class="line"> -w, --check-chars=N      <span class="comment">//对每行第N 个字符以后的内容不作对照  </span></span><br><span class="line"> --help              <span class="comment">//显示此帮助信息并退出  </span></span><br><span class="line"> --version              <span class="comment">//显示版本信息并退出 </span></span><br><span class="line">显示有重复的行</span><br><span class="line">$ uniq -d -c uniqtest  </span><br><span class="line">  <span class="number">3</span> <span class="keyword">this</span> is a test  </span><br><span class="line">  <span class="number">2</span> i love tank </span><br><span class="line">  uniq -D 只显示重复的行，并且把重复几行都显示出来。他不能和-c一起使用</span><br><span class="line">  仅显示不重复的行 sort testfile | uniq -u</span><br></pre></td></tr></table></figure>
<h3 id="curl"><a href="#curl" class="headerlink" title="curl"></a>curl</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">查询访问时间</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> &#123;<span class="number">1.</span><span class="number">.100</span>&#125;;<span class="keyword">do</span> curl -o /dev/<span class="literal">null</span> -s   -w <span class="string">"$i | time_namelookup: %&#123;time_namelookup&#125; | time_connect: %&#123;time_connect&#125; | time_starttransfer: %&#123;time_starttransfer&#125; | time_total: %&#123;time_total&#125;\n"</span> -x <span class="string">"10.71.48.129:80"</span> <span class="string">"http://www.baidu.com"</span>; done</span><br></pre></td></tr></table></figure>
<h3 id="ftp"><a href="#ftp" class="headerlink" title="ftp"></a>ftp</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">yum install vsftpd</span><br><span class="line">启动ftp命令#service vsftpd start</span><br><span class="line"></span><br><span class="line">停止ftp命令#service vsftpd stop</span><br><span class="line"></span><br><span class="line">重启ftp命令#service vsftpd restart</span><br><span class="line">[root@VM_0_14_centos ~]# useradd test</span><br><span class="line">[root@VM_0_14_centos ~]# passwd test</span><br><span class="line">Changing password <span class="keyword">for</span> user test.</span><br><span class="line">New password:</span><br><span class="line">BAD PASSWORD: The password is shorter than <span class="number">8</span> characters</span><br><span class="line">Retype <span class="keyword">new</span> password:</span><br><span class="line">Sorry, passwords <span class="keyword">do</span> not match.</span><br><span class="line">New password:</span><br><span class="line">Retype <span class="keyword">new</span> password:</span><br><span class="line">passwd: all authentication tokens updated successfully.</span><br><span class="line">[root@VM_0_14_centos ~]# ll /home/test/</span><br><span class="line">total <span class="number">0</span></span><br><span class="line">[root@VM_0_14_centos ~]# cd /home/test/</span><br><span class="line">[root@VM_0_14_centos test]# touch test.php</span><br><span class="line">然后使用filezilla链接ftp test账号登录看到的就是/home/test/下的文件</span><br></pre></td></tr></table></figure>
<h3 id="git"><a href="#git" class="headerlink" title="git"></a>git</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">使用通配符提交 git add *.js</span><br><span class="line">只删除版本库中文件但保存项目目录中文件 git rm --cached index.php</span><br><span class="line">放弃没有提交的修改 git checkout .</span><br><span class="line">删除没有add 的文件和目录 git clean -fd</span><br><span class="line">显示将要删除的文件或目录 git clean -n</span><br><span class="line">查看最近<span class="number">2</span>次提交日志并显示文件差异 git log -p <span class="number">-2</span></span><br><span class="line">一行显示并只显示SHA<span class="number">-1</span>的前几个字符 git log --oneline</span><br><span class="line">git config --global alias.c commit 使用 git c 实现 git commit  一样的效果了</span><br><span class="line">$ git log --graph --pretty=format:<span class="string">'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset'</span> --abbrev-commit</span><br><span class="line">*   <span class="number">1</span>edc0f8c - (HEAD -&gt; temp, origin/master, origin/HEAD, master) Merge branch <span class="string">'master'</span> into temp (<span class="number">3</span> hours ago) &lt;xxx&gt;</span><br><span class="line">|\</span><br><span class="line">| * <span class="number">7</span>bd6895a - Merge branch <span class="string">'dev'</span>pay/right优化 (<span class="number">5</span> hours ago) &lt;xxx&gt;</span><br><span class="line">| *   d81f7be5 - Merge branch <span class="string">'temp'</span> (<span class="number">6</span> hours ago) &lt;xxx&gt;</span><br><span class="line">创建并切换分支 git checkout -b feature/bbs</span><br><span class="line">删除远程分支 git push origin :dev</span><br><span class="line">储藏工作 git stash</span><br><span class="line">查看储藏列表 git stash list</span><br><span class="line">应用最近的储藏 git stash apply</span><br><span class="line">应用并删除储藏 git stash pop</span><br><span class="line">对mster分支代码生成压缩包供使用者下载使用，--prefix 指定目录名</span><br><span class="line">git archive master --prefix=<span class="string">'hdcms/'</span> --format=zip &gt; hdcms.zip</span><br><span class="line"></span><br><span class="line">删除远程ask分支 git push origin --<span class="keyword">delete</span> ask</span><br><span class="line">本地ask分支关联远程分支并推送 git push --set-upstream origin ask</span><br><span class="line"># 增加一个远程库</span><br><span class="line">git remote add github git@github.com:houdunwang/coding.git</span><br><span class="line"></span><br><span class="line"># 提交到远程库</span><br><span class="line">git push github</span><br><span class="line">git remote add origin git@github.com:houdunwang/hd-xj.git</span><br><span class="line">拉取origin主机的ask分支与本地的master分支合并 git pull origin ask:ask</span><br><span class="line">拉取origin主机的ask分支与当前分支合并 git pull origin ask</span><br></pre></td></tr></table></figure>
<h3 id="查找清理大文件"><a href="#查找清理大文件" class="headerlink" title="查找清理大文件"></a>查找清理大文件</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">[cuihuan:~ cuixiaohuan]$ df -h</span><br><span class="line">Filesystem Size Used Avail Use% Mounted on</span><br><span class="line">/dev/sda2 <span class="number">8.2</span>G <span class="number">6.7</span>G <span class="number">1.6</span>G <span class="number">82</span>% <span class="regexp">/</span></span><br><span class="line"><span class="regexp">/</span>dev/sda3 <span class="number">1.4</span>T <span class="number">1.3</span>T <span class="number">50</span>G <span class="number">97</span>% <span class="regexp">/home</span></span><br><span class="line"><span class="regexp">1.5T的硬盘占用了97%，确实不够用了</span></span><br><span class="line"><span class="regexp">[cuihuan:~]$ du -sh * | grep G</span></span><br><span class="line"><span class="regexp">。。。</span></span><br><span class="line"><span class="regexp">73G mongodb</span></span><br><span class="line"><span class="regexp">103G mxm</span></span><br><span class="line"><span class="regexp">2.1G online</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">http:/</span><span class="regexp">/cuihuan.net/</span><span class="number">2015</span>/<span class="number">12</span>/<span class="number">08</span>/linux%<span class="number">20</span>%E6%<span class="number">9</span>F%A5%E6%<span class="number">89</span>%BE%E6%B8%<span class="number">85</span>%E7%<span class="number">90</span>%<span class="number">86</span>%E5%A4%A7%E6%<span class="number">96</span>%<span class="number">87</span>%E4%BB%B6/</span><br></pre></td></tr></table></figure>
<h3 id="crontab-误删除恢复"><a href="#crontab-误删除恢复" class="headerlink" title="crontab 误删除恢复"></a>crontab 误删除恢复</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">cat /<span class="keyword">var</span>/log/cron | grep -i <span class="string">"`which cron`"</span> &gt; ./all_temp</span><br><span class="line">cat  ./all_temp | grep -v <span class="string">"&lt;command&gt;” &gt; ./cmd_temp</span></span><br><span class="line"><span class="string">awk -F'(' '/crond/&#123;a[$3]=$0&#125;END&#123;for(i in a)print a[i]&#125;' /var/log/cron* &gt;crontab.txt</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">从crontab.txt 中找出每一条指令，然后在cmd_temp 中匹配运行次数，重新编辑crontab 添加</span></span><br><span class="line"><span class="string">每天对crontab进行备份，备份最近15天的数据。</span></span><br><span class="line"><span class="string">#!/bin/bash</span></span><br><span class="line"><span class="string"># 每天对crontab 进行备份 ，同时删除最近15天的数据</span></span><br><span class="line"><span class="string">DATE=$(date +%Y%m%d)</span></span><br><span class="line"><span class="string">crontab -l &gt; /home/work/bak/crontab_$DATE.bak</span></span><br><span class="line"><span class="string">find /home/work/bak/ -mtime +15 -name '*.bak' -exec rm -rf &#123;&#125; \;</span></span><br><span class="line"><span class="string">http://cuihuan.net/2015/12/03/crontab%20%E8%AF%AF%E5%88%A0%E9%99%A4%E6%81%A2%E5%A4%8D/</span></span><br></pre></td></tr></table></figure>
<h3 id="tail-grep"><a href="#tail-grep" class="headerlink" title="tail grep"></a>tail grep</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//itbilu.com/linux/man/H1_dxWhz4.html</span></span><br><span class="line">现有itbilu.log日志文件，查看其后<span class="number">5</span>行：</span><br><span class="line"></span><br><span class="line">$ tail -n <span class="number">-5</span> itbilu.log</span><br><span class="line"><span class="comment">// 或</span></span><br><span class="line">$ tail -n <span class="number">5</span> itbilu.log</span><br><span class="line"><span class="comment">// 或</span></span><br><span class="line">$ tail <span class="number">-5</span> itbilu.log</span><br><span class="line">查看第<span class="number">100</span>行至文件末尾：</span><br><span class="line"></span><br><span class="line">$ tail -n +<span class="number">100</span> itbilu.log</span><br><span class="line"><span class="comment">// 或</span></span><br><span class="line">$ tail +<span class="number">100</span> itbilu.log</span><br><span class="line">配合head命令，实现查看文件的第<span class="number">10</span>到<span class="number">20</span>行：</span><br><span class="line"></span><br><span class="line">$ head <span class="number">-20</span> itbilu.log | tail <span class="number">-10</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">实时查看日志</span><br><span class="line"></span><br><span class="line">通过-f参数，我们可以实时查看文件的新增内容：</span><br><span class="line"></span><br><span class="line">$ tail -f itbilu.log</span><br><span class="line">注意：使用-f参数时不会中断文件监视，需要通过ctrl+c手动结束。</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">实时日志查看与grep过滤关键字</span><br><span class="line"></span><br><span class="line">通过-f参数，并配合grep命令，可以实现对文件内容的过滤。如：查看前几行、后几行、或前后几行，这时可以通过以下几个参数实现：</span><br><span class="line"></span><br><span class="line">-A &lt;显示行数&gt;            除了显示符合匹配内容的那一行之外，并显示该行之后的内容</span><br><span class="line">-B &lt;显示行数&gt;            在显示符合匹配内容的那一行之外，并显示该行之前的内容</span><br><span class="line">-C &lt;显示行数&gt;或-&lt;显示行数&gt; 除了显示符合匹配内容的那一列之外，并显示该列之前后的内容</span><br><span class="line">监控itbilu.log日志件，并查看含有'foo'关键字的前后5行：</span><br><span class="line"></span><br><span class="line">$ tail -f itbilu.log|grep 'foo' -C 5</span><br><span class="line">// 或</span><br><span class="line">$ tail -f itbilu.log|grep 'foo' -5</span><br><span class="line"></span><br><span class="line">查找/code目录下js文件，显示包括itbilu.com的行。命令如下：</span><br><span class="line"></span><br><span class="line"># find ./code -name '*.js'|xargs grep -n 'itiblu.com'</span><br><span class="line"># expr 10 + 20</span><br><span class="line">30</span><br><span class="line"></span><br><span class="line">用expr命令计算字符串的长度。命令如下：</span><br><span class="line"></span><br><span class="line"># str="hello world"</span><br><span class="line"># expr length "$str"</span><br><span class="line">11</span><br><span class="line"></span><br><span class="line"> $ stat routes.php</span><br><span class="line">  File: `routes.php'</span><br><span class="line">  Size: 24191           Blocks: 48         IO Block: 4096   regular file</span><br><span class="line">Device: 811h/2065d      Inode: 7217947     Links: 1</span><br><span class="line">Access: (0775/-rwxrwxr-x)  Uid: (  611/ UNKNOWN)   Gid: (  612/ UNKNOWN)</span><br><span class="line">Access: 2019-10-12 15:21:30.733152751 +0800</span><br><span class="line">Modify: 2018-12-14 14:23:34.406787125 +0800</span><br><span class="line">Change: 2018-12-14 14:23:34.406787125 +0800</span><br><span class="line">现有file1和file2两个文件，file内容为1121，file2内容为1123。比较file1和file2两个文件的差异，参数如下：</span><br><span class="line"></span><br><span class="line">cmp file1 file2</span><br><span class="line">比较file1和file2两个文件的差异，然后使用diffstat命令对结果进行统计显示。命令如下：</span><br><span class="line"></span><br><span class="line">diff file1 file2 | diffstat</span><br></pre></td></tr></table></figure>
<h3 id="sudo-command-not-found"><a href="#sudo-command-not-found" class="headerlink" title="sudo command not found"></a>sudo command not found</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">在 env_keep 中增加 PATH 字段</span><br><span class="line"></span><br><span class="line">vim /etc/sudoers</span><br><span class="line">Defaults    env_keep += <span class="string">"LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY PATH"</span></span><br><span class="line"># 注释掉 secure_path</span><br><span class="line">#Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin</span><br></pre></td></tr></table></figure>
<h3 id="避免-rm-误操作"><a href="#避免-rm-误操作" class="headerlink" title="避免 rm 误操作"></a>避免 rm 误操作</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">wget https:<span class="comment">//github.com/LaiJingli/rmtrash/blob/master/rmtrash.sh</span></span><br><span class="line">mv rmtrash.sh /usr/local/bin #移动到bin目录下</span><br><span class="line">chmod +x /bin/rmtrash.sh #增加可执行权限</span><br><span class="line">vim ~<span class="regexp">/.bashrc</span></span><br><span class="line"><span class="regexp">#增加别名</span></span><br><span class="line"><span class="regexp">alias rm=/</span>bin/rmtrash.sh</span><br><span class="line">rmtrash -h #帮助命令</span><br><span class="line">rmtrash -e #清空回收站</span><br><span class="line">https:<span class="comment">//learnku.com/articles/35041</span></span><br></pre></td></tr></table></figure>
<h3 id="awk-1"><a href="#awk-1" class="headerlink" title="awk"></a>awk</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">系统突然出现卡顿，常用的排查思路有哪些呢？</span><br><span class="line"></span><br><span class="line">查看内存使用状况：free -g</span><br><span class="line">查看磁盘使用状况：df -h</span><br><span class="line">查看磁盘 I/O 使用：iostat -dx</span><br><span class="line">查看 CPU 使用：top</span><br><span class="line">[release@api_02 ~]$ last -n <span class="number">5</span> | awk <span class="string">'&#123;print $1 "\t lines:" NR "\t columns:"NF&#125;'</span></span><br><span class="line">release  lines:<span class="number">1</span>     columns:<span class="number">10</span></span><br><span class="line">release  lines:<span class="number">2</span>     columns:<span class="number">10</span></span><br><span class="line">release  lines:<span class="number">3</span>     columns:<span class="number">10</span></span><br><span class="line">release  lines:<span class="number">4</span>     columns:<span class="number">10</span></span><br><span class="line">release  lines:<span class="number">5</span>     columns:<span class="number">10</span></span><br></pre></td></tr></table></figure>
<p>有洁癖的同学可以使用 docker-compose，推荐一下自己构建的（<a href="https://gitee.com/nxs/docker-compose）" target="_blank" rel="noopener">https://gitee.com/nxs/docker-compose）</a>  </p>
<p><a href="https://learnku.com/articles/28500" target="_blank" rel="noopener">最好的 Linux 桌面版—- Windows 10 安装体验 </a></p>
<p><a href="https://segmentfault.com/a/1190000016837948" target="_blank" rel="noopener">linux 常用命令top、awk、sed等</a></p>
<p><a href="http://blog.51yip.com/shell/986.html" target="_blank" rel="noopener">sed很强大的文本操作命令</a></p>
<p><a href="http://blog.51yip.com/server/1960.html" target="_blank" rel="noopener">ubuntu sentry 安装配置</a></p>
<p><a href="https://linux.cn/article-10342-shareweibo.html" target="_blank" rel="noopener">数据科学家的命令行技巧</a></p>
<p><a href="https://laravel-china.org/articles/21339" target="_blank" rel="noopener">xargs 命令详解</a></p>
<p><a href="https://github.com/jlevy/the-art-of-command-line/blob/master/README-zh.md" target="_blank" rel="noopener">Linux 命令行的艺术</a></p>
<p><a href="http://blog.51yip.com/shell/1022.html" target="_blank" rel="noopener">linux下去除重复行命令uniq</a></p>
<p><a href="https://gywbd.github.io/posts/2014/8/50-linux-commands.html" target="_blank" rel="noopener">50个最常用的Unix/Linux命令 </a></p>
<p><a href="https://mp.weixin.qq.com/s/6YVC9hA2fMEjclWmseevXA" target="_blank" rel="noopener">看示例学awk</a></p>
<p><a href="https://linux.cn/article-10232-1.html" target="_blank" rel="noopener">Sed 命令完全指南 </a></p>
<p><a href="https://www.centos.bz/2017/07/nginx-awk-access-log/" target="_blank" rel="noopener">awk查看统计Nginx访问日志</a></p>
<p><a href="https://www.centos.bz/2018/11/sed%E4%B8%80%E4%BA%9B%E5%B8%B8%E7%94%A8%E7%9A%84%E5%91%BD%E4%BB%A4%E8%AF%A6%E8%A7%A3/" target="_blank" rel="noopener">Sed:一些常用的命令详解</a></p>
<p><a href="https://laravel-china.org/articles/21602" target="_blank" rel="noopener">提高工作效率的 VIM 操作</a></p>
<p><a href="https://laravel-china.org/articles/21832" target="_blank" rel="noopener">Git 基本使用文档</a></p>
<p><a href="https://learnku.com/articles/28904" target="_blank" rel="noopener">网络问题连不上网</a></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/linux/" rel="tag"># linux</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/12/18/有用的网站和工具/" rel="next" title="有用的网站和工具">
                <i class="fa fa-chevron-left"></i> 有用的网站和工具
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/01/07/代码段收集/" rel="prev" title="代码段收集">
                代码段收集 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
          <div class="comments" id="comments">
             <div id="gitment-container"></div>
         </div>
  




        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">苏生不惑</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">382</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">37</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/sushengbuhuo" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mysusheng@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://plus.google.com/mysusheng" target="_blank" title="Google">
                      
                        <i class="fa fa-fw fa-google"></i>Google</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://v2ex.com/" title="v2ex" target="_blank">v2ex</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.fanhaobai.com/" title="fanhaobai" target="_blank">fanhaobai</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="yuanxuxu" target="_blank">yuanxuxu</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.snail-c.cn/article" title="snail-c" target="_blank">snail-c</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://showcj.com/archives" title="showcj" target="_blank">showcj</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://vultr.aicnm.com/%E6%9C%80%E6%96%B0Vultr%E6%B3%A8%E5%86%8C%E5%8F%8AVPS%E8%B4%AD%E4%B9%B0%E5%9B%BE%E6%96%87%E6%95%99%E7%A8%8B/" title="vultr" target="_blank">vultr</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lucissfer.com/" title="lucissfer" target="_blank">lucissfer</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.csdn.net/fdipzone/article/details/79352685" title="傲雪星枫" target="_blank">傲雪星枫</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yoby123.cn/index.php/category/default/" title="小白的分享" target="_blank">小白的分享</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/p/5819995.html" title="PHP攻城狮" target="_blank">PHP攻城狮</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.jiaojie.site/" title="php" target="_blank">php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://sphard.com/archives/" title="sphard" target="_blank">sphard</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="LNMP技术栈笔记" target="_blank">LNMP技术栈笔记</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.coding10.com/" title="学习 Laravel" target="_blank">学习 Laravel</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://shuwoom.com/?page_id=929" title="区块链学习指南" target="_blank">区块链学习指南</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://greenlightt.github.io/archives/" title="greenlightt" target="_blank">greenlightt</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.0php.net/archives/" title="0php" target="_blank">0php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.fordba.com/category/mysql" title="mysql" target="_blank">mysql</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.itcodemonkey.com/" title="程序员" target="_blank">程序员</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yanshuo.me/r/v2ex" title="言说" target="_blank">言说</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.timiguo.com/archive.html" title="提米果的博客" target="_blank">提米果的博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://phpartisan.cn/news/112.html" title="phpartisan" target="_blank">phpartisan</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/" title="飞鸿影" target="_blank">飞鸿影</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.54php.cn/" title="54php" target="_blank">54php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lazyman.vip/" title="营销" target="_blank">营销</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.njphper.com/archives/" title="做人呢最重要的就是开心" target="_blank">做人呢最重要的就是开心</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.h57.pw/" title="php 初心者" target="_blank">php 初心者</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#sed"><span class="nav-number">1.</span> <span class="nav-text">sed</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#sort"><span class="nav-number">2.</span> <span class="nav-text">sort</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#cut"><span class="nav-number">3.</span> <span class="nav-text">cut</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#合并文件"><span class="nav-number">4.</span> <span class="nav-text">合并文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#awk"><span class="nav-number">5.</span> <span class="nav-text">awk</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#快捷键"><span class="nav-number">6.</span> <span class="nav-text">快捷键</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解压"><span class="nav-number">7.</span> <span class="nav-text">解压</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#测试并发"><span class="nav-number">8.</span> <span class="nav-text">测试并发</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查看当前目录下各个文件或文件夹的大小"><span class="nav-number">9.</span> <span class="nav-text">查看当前目录下各个文件或文件夹的大小</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查找字符串"><span class="nav-number">10.</span> <span class="nav-text">查找字符串</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Nginx-日志统计-ip-访问数"><span class="nav-number">11.</span> <span class="nav-text">Nginx 日志统计 ip 访问数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#文件比较（交集、差集）"><span class="nav-number">12.</span> <span class="nav-text">文件比较（交集、差集）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#转换编码"><span class="nav-number">13.</span> <span class="nav-text">转换编码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#执行算术运算"><span class="nav-number">14.</span> <span class="nav-text">执行算术运算</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#send-email"><span class="nav-number">15.</span> <span class="nav-text">send email</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#wc"><span class="nav-number">16.</span> <span class="nav-text">wc</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#kill"><span class="nav-number">17.</span> <span class="nav-text">kill</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#uniq"><span class="nav-number">18.</span> <span class="nav-text">uniq</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#curl"><span class="nav-number">19.</span> <span class="nav-text">curl</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ftp"><span class="nav-number">20.</span> <span class="nav-text">ftp</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git"><span class="nav-number">21.</span> <span class="nav-text">git</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查找清理大文件"><span class="nav-number">22.</span> <span class="nav-text">查找清理大文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#crontab-误删除恢复"><span class="nav-number">23.</span> <span class="nav-text">crontab 误删除恢复</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#tail-grep"><span class="nav-number">24.</span> <span class="nav-text">tail grep</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#sudo-command-not-found"><span class="nav-number">25.</span> <span class="nav-text">sudo command not found</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#避免-rm-误操作"><span class="nav-number">26.</span> <span class="nav-text">避免 rm 误操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#awk-1"><span class="nav-number">27.</span> <span class="nav-text">awk</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">苏生不惑</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>



<div>
<span id="showDays"></span>

</div>

<span id="busuanzi_container_site_pv">
   总访问量:<span id="busuanzi_value_site_pv"></span>次
</span>



  <span class="post-meta-divider">|</span>



<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共773.8k字</span>
</div>
<script>
var birthDay = new Date("11/20/2018");
var now = new Date();
var duration = now.getTime() - birthDay.getTime();
var total= Math.floor(duration / (1000 * 60 * 60 * 24));
document.getElementById("showDays").innerHTML = "本站已运行 "+total+" 天";
</script>

        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  











<script type="text/javascript">
    (function() {
        // 匿名函数，防止污染全局变量
        var utterances = document.createElement('script');
        utterances.type = 'text/javascript';
        utterances.async = true;
        utterances.setAttribute('issue-term','0')
        utterances.setAttribute('theme','')
        utterances.setAttribute('repo','sushengbuhuo/laravel_ioc_demo')
        utterances.crossorigin = 'anonymous';
        utterances.src = 'https://utteranc.es/client.js';
        // content 是要插入评论的地方
        document.getElementById('gitment-container').appendChild(utterances);
    })();
</script>


  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

  
<script>
  ((window.gitter = {}).chat = {}).options = {
    //room替换成自己的聊天室名称即可，room的名称规则是：username/roomname
    room: 'sushengbuhuo-chat/mychat'
  };
</script>
<script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer></script>

</body>
</html>
